I was reviewing a piece of code written by someone else that created global variables in the topmost context in order to pass buffer data out of code that was executing in an eval_ statement.
So, first the code, then the explanation: int Chk = LeakCheck Buffer dxlString = create dxlString += "print \"Running in eval\\n\"\n" dxlString += "Buffer theErrors_ = create\n" dxlString += "theErrors_ += \"A constructed string made via a buffer\"\n" dxlString += "return_(tempStringOf(theErrors_))\n" Buffer result = create result = eval_(tempStringOf(dxlString)) delete dxlString print tempStringOf result delete result print "\n" (LeakCheck()-Chk) ""
I should first say that the "LeakCheck" routine is basically Mathias's leak checking code slightly rewritten and renamed - but functionally pretty much the same.
p.s. HINT: It is actually line 6 in the code that is potentially contentious, not line 8 or line 10 Also, the code may be depending on the fact that the return_ is the last statement in the evaluated script.
AlexTidmarsh - Tue May 19 23:54:58 EDT 2015 |
Re: Is this slightly scary use of "tempStringOf" viable?
I can already hear one response to this (because it is what I would suggest), so I will deal with that now:
|
Re: Is this slightly scary use of "tempStringOf" viable?
Incidentally, the result output I get from the dxl-edit window is: Running in eval A constructed string made via a buffer 0
|
Re: Is this slightly scary use of "tempStringOf" viable?
As an afterthought, a real test of this would be to load the script directly from a file into a buffer - thus not polluting the string table with anything at all. And then run some code that displays the string table after executing the eval_.
|
Re: Is this slightly scary use of "tempStringOf" viable? AlexTidmarsh - Wed May 20 00:42:11 EDT 2015
As an afterthought, a real test of this would be to load the script directly from a file into a buffer - thus not polluting the string table with anything at all. And then run some code that displays the string table after executing the eval_.
Hi Alex, I am pretty sure that this approach does not save you from string table littering. The return_ statement will very likely produce a string table entry, the question is, if its permanent or not. You can test this however: (String Table Code is here: https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014886977&ps=25)
#include <D:/petools.inc>
#include <D:/stringTable.inc>
printStringTable()
int i; for (i = 0; i < 100; i++) {
Buffer buf = create();
buf += "Buffer z = create()\n"
buf += "int i; for (i = 0; i < 100; i++) {\n"
buf += "z += charOf ((random 64) + 64)\n"
buf += "}\n"
// buf += "return_ tempStringOf z" // Comment me in to get string table littering
eval_ tempStringOf buf;
delete buf
}
printStringTable()
As you can see, inside the val we are constructing 100char random strings inside a buffer without any string table littering. Once you comment in the the return_ statement the strings will be persisted in the string table. You can see that with every start of the script the string table entries will rise by 100. Therefore if you want to pass a string out from an eval_ context you should use a static eval code with a buffer reference. It is perfectly allowed to write to a parent DXL context buffer from a child context. You will not even need a global variable for this:
#include <D:/petools.inc>
#include <D:/stringTable.inc>
printStringTable()
int i; for (i = 0; i < 100; i++) {
Buffer buf = create();
Buffer result = create();
buf += "Buffer z = addr_ "
buf += ((addr_ result) int) ""
buf += "\nint i; for (i = 0; i < 100; i++) {\n"
buf += "z += charOf ((random 64) + 64)\n"
buf += "}\n"
eval_ tempStringOf buf;
delete buf
print (tempStringOf result);
delete result
}
printStringTable()
And if you want to save yourself the time and the non-permanent string table entries for converting the buffer address to a string, then you should use static DXL code and use references to access the buffers. This way you will not need to assemble the code inside the buffer every time you call the function: (Note that in that example you would not need to pass the buffer into the eval context by reference). No need to fear global variables in DXL. They might be discouraged for other programming languages but for DXL they are an imperative. Regards, Mathias
|
Re: Is this slightly scary use of "tempStringOf" viable? Mathias Mamsch - Wed May 20 09:59:43 EDT 2015 Hi Alex, I am pretty sure that this approach does not save you from string table littering. The return_ statement will very likely produce a string table entry, the question is, if its permanent or not. You can test this however: (String Table Code is here: https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014886977&ps=25)
#include <D:/petools.inc>
#include <D:/stringTable.inc>
printStringTable()
int i; for (i = 0; i < 100; i++) {
Buffer buf = create();
buf += "Buffer z = create()\n"
buf += "int i; for (i = 0; i < 100; i++) {\n"
buf += "z += charOf ((random 64) + 64)\n"
buf += "}\n"
// buf += "return_ tempStringOf z" // Comment me in to get string table littering
eval_ tempStringOf buf;
delete buf
}
printStringTable()
As you can see, inside the val we are constructing 100char random strings inside a buffer without any string table littering. Once you comment in the the return_ statement the strings will be persisted in the string table. You can see that with every start of the script the string table entries will rise by 100. Therefore if you want to pass a string out from an eval_ context you should use a static eval code with a buffer reference. It is perfectly allowed to write to a parent DXL context buffer from a child context. You will not even need a global variable for this:
#include <D:/petools.inc>
#include <D:/stringTable.inc>
printStringTable()
int i; for (i = 0; i < 100; i++) {
Buffer buf = create();
Buffer result = create();
buf += "Buffer z = addr_ "
buf += ((addr_ result) int) ""
buf += "\nint i; for (i = 0; i < 100; i++) {\n"
buf += "z += charOf ((random 64) + 64)\n"
buf += "}\n"
eval_ tempStringOf buf;
delete buf
print (tempStringOf result);
delete result
}
printStringTable()
And if you want to save yourself the time and the non-permanent string table entries for converting the buffer address to a string, then you should use static DXL code and use references to access the buffers. This way you will not need to assemble the code inside the buffer every time you call the function: (Note that in that example you would not need to pass the buffer into the eval context by reference). No need to fear global variables in DXL. They might be discouraged for other programming languages but for DXL they are an imperative. Regards, Mathias
Thanks for this, Mathias. I shall have to spend some time with this to get my head around it. As for the comment about global variables, I understand what you mean - but the general discouragement of global variables is not anything to do with language - they are bad practice in a language-independent way. The fact that DXL kind of forces you to use them IMHO is just another measure of how poorly designed the language is. :-) p.s. as a lifelong practitioner (30 years worth) of programming embedded systems with C, I have come to truly hate that language too. But we all program where the money takes us. - Delphi (extended Pascal) is the language I hate the least. :-) It's a productivity thing. I can write a thousand lines of debugged working Pascal code in the time it takes to write 100 lines of debugged working C or 20 lines of DXL that might just about work. (And as the question is begged: 1,000 lines of Pascal? three to five days, probably). ok. there may be a small bit of proportional exaggeration for effect - but the real measure is the deepness of the sigh I emit when I realise which language I am going to have to use for a job.
But back to the point... Temporary string table littering? Ok, that sounds like a good thing.
|
Re: Is this slightly scary use of "tempStringOf" viable? AlexTidmarsh - Thu May 21 01:40:52 EDT 2015 Thanks for this, Mathias. I shall have to spend some time with this to get my head around it. As for the comment about global variables, I understand what you mean - but the general discouragement of global variables is not anything to do with language - they are bad practice in a language-independent way. The fact that DXL kind of forces you to use them IMHO is just another measure of how poorly designed the language is. :-) p.s. as a lifelong practitioner (30 years worth) of programming embedded systems with C, I have come to truly hate that language too. But we all program where the money takes us. - Delphi (extended Pascal) is the language I hate the least. :-) It's a productivity thing. I can write a thousand lines of debugged working Pascal code in the time it takes to write 100 lines of debugged working C or 20 lines of DXL that might just about work. (And as the question is begged: 1,000 lines of Pascal? three to five days, probably). ok. there may be a small bit of proportional exaggeration for effect - but the real measure is the deepness of the sigh I emit when I realise which language I am going to have to use for a job.
But back to the point... Temporary string table littering? Ok, that sounds like a good thing.
Actually, I can already here my friend and colleague Peter saying - if you stop fighting the language your productivity could go up. To which I of course would counter: yey! 1,000 lines of DXL that works... for now... |
Re: Is this slightly scary use of "tempStringOf" viable? AlexTidmarsh - Thu May 21 01:40:52 EDT 2015 Thanks for this, Mathias. I shall have to spend some time with this to get my head around it. As for the comment about global variables, I understand what you mean - but the general discouragement of global variables is not anything to do with language - they are bad practice in a language-independent way. The fact that DXL kind of forces you to use them IMHO is just another measure of how poorly designed the language is. :-) p.s. as a lifelong practitioner (30 years worth) of programming embedded systems with C, I have come to truly hate that language too. But we all program where the money takes us. - Delphi (extended Pascal) is the language I hate the least. :-) It's a productivity thing. I can write a thousand lines of debugged working Pascal code in the time it takes to write 100 lines of debugged working C or 20 lines of DXL that might just about work. (And as the question is begged: 1,000 lines of Pascal? three to five days, probably). ok. there may be a small bit of proportional exaggeration for effect - but the real measure is the deepness of the sigh I emit when I realise which language I am going to have to use for a job.
But back to the point... Temporary string table littering? Ok, that sounds like a good thing.
Regarding temporary string table littering: I realized, that strings that were never passed to a perm are not persisted permanently in the string table but only temporary.
If you do code like: This will also create string table entries, but they will be cleared when the DXL ends. That is what I call "temporary string table littering".
Regards, Mathias |
Re: Is this slightly scary use of "tempStringOf" viable? Mathias Mamsch - Mon May 25 04:45:04 EDT 2015 Regarding temporary string table littering: I realized, that strings that were never passed to a perm are not persisted permanently in the string table but only temporary.
If you do code like: This will also create string table entries, but they will be cleared when the DXL ends. That is what I call "temporary string table littering".
Regards, Mathias
I'm sorry? Do my ears/eyes deceive me?
s = "Hello for the " count "th time"; print s;
That really does put a new spin on my previous understanding! :-)
(Unless, of course, this is a game of catch-22 and the '=' is one of those perms!) (Confused face) ...define "perm" in this context, please... does it exclude operators and their overloads, or is it an even smaller subset than that?
|
Re: Is this slightly scary use of "tempStringOf" viable? AlexTidmarsh - Tue May 26 04:52:25 EDT 2015
I'm sorry? Do my ears/eyes deceive me?
s = "Hello for the " count "th time"; print s;
That really does put a new spin on my previous understanding! :-)
(Unless, of course, this is a game of catch-22 and the '=' is one of those perms!) (Confused face) ...define "perm" in this context, please... does it exclude operators and their overloads, or is it an even smaller subset than that?
well - most perms? I am not entirely sure - After all the ::.. (concatenation operator) is also a perm, as is "=" - no these perms do not produce permanent string table entries. Why or which perms exactly produce permanent string table entries - I can only speculate, but I was wrong lots of times with speculations so I would not even try. "Print" does not by the way, but from trying most other relevant perms do. If you find a "scheme" or something, then let us know. Regards, Mathias |
Re: Is this slightly scary use of "tempStringOf" viable? Mathias Mamsch - Tue May 26 07:41:37 EDT 2015 well - most perms? I am not entirely sure - After all the ::.. (concatenation operator) is also a perm, as is "=" - no these perms do not produce permanent string table entries. Why or which perms exactly produce permanent string table entries - I can only speculate, but I was wrong lots of times with speculations so I would not even try. "Print" does not by the way, but from trying most other relevant perms do. If you find a "scheme" or something, then let us know. Regards, Mathias
Print doesn't !?!
s = "Hello for the " count "th time"; print s;
only pollutes the string table temporarily then. |
Re: Is this slightly scary use of "tempStringOf" viable? Didn't read the replies, or in fact your entire post. The string returned from "tempStringOf" is reliable only while you subsequently neither replace the contents nor delete the source Buffer. I'm guessing you can safely ADD more string to the Buffer. The "tempStringOf" for the eval_ seems reasonable. I think, and I repeat <think> it is stable enough for the duration of the eval_ all because the Buffer in which it resides is continuing to exist and is not modified inside the eval_.
The "tempStringOf" of the Results is reasonable only because you are disposing of it immediately; printing it and you are done. This in fact is the standard use of "tempStringOf": displose of the string and move on. -Louie |
Re: Is this slightly scary use of "tempStringOf" viable? llandale - Wed May 27 20:45:20 EDT 2015 Didn't read the replies, or in fact your entire post. The string returned from "tempStringOf" is reliable only while you subsequently neither replace the contents nor delete the source Buffer. I'm guessing you can safely ADD more string to the Buffer. The "tempStringOf" for the eval_ seems reasonable. I think, and I repeat <think> it is stable enough for the duration of the eval_ all because the Buffer in which it resides is continuing to exist and is not modified inside the eval_.
The "tempStringOf" of the Results is reasonable only because you are disposing of it immediately; printing it and you are done. This in fact is the standard use of "tempStringOf": displose of the string and move on. -Louie I have now been using this return mechanism in a real system since the date of the original post, and no-one has noticed any faults occurring, so I'm guessing the consensus is that, yes, it is viable - taking your point about its lifetime into account. After the discussion with Mathias, the question now becomes: is it actually beneficial? (Beyond the avoidance of using global variables and/or the use of hard-to-read constructs like the one Mathias demonstrated - and I have also used in the past, incidentally). Yes: the assignment direct from the eval_ result into a new buffer effectively ends the tempStringOf lifecycle started within the return_ and passed out of the eval_ there and then: noting in particular that there are no more statements in the evaluated script after the return_ and no other use made of the eval_ result other than to immediately put it into a buffer. So on the face of it, it (sort of) meets the limitations of use you have stated. Usage thus far has certainly not raised any errors.
From what Mathias has said, any temporary string table pollution caused during the evaluated script should also end immediately with the end of the eval_ context (along with any undeleted buffers, etc). So: not only does it appear to work as a transfer mechanism, it is possibly beneficial: noting that the "usual" way of doing this is for the "return_" to process an actual string (permanent? from the string table?) rather than a pointer into a buffer (tempStringOf). Although the only way to know if it is beneficial is to know whether the "normal" way pollutes the string table (temporarily or permanently) in the memory space (context) of the caller of the eval_. Mathias has effectively begged that question. In theory, the tempStringOf method I've proposed shouldn't even pollute it temporarily - but it is beginning to look like it does. Which means my assumption about the context destruction after the final assignment may be slightly wrong - and is being "masked" by the use of a temporary string table entry being created in the caller's memory space as part of the "tail-end" work of the eval_ perm.
P.S. Louie, if you do read the whole thread thus far, you'll notice the bit about deleting the buffer within the script and its effect on the preceding return_ and eventual final eval_ result, which suggested that the pointer is passed through "as-is" without putting it into a string table, temporarily or permanently. It also appeared to me that the final destruction of the memory space (i.e. context) of the evaluated script occurs just after the eval's final assignment. If it didn't, then this trick with tempStringOf wouldn't be working - in the same way that it doesn't if I expressly delete the buffer in the script. However - the question is begged by Mathias whether the transfer between return_ and eval_ at the very point of destroying the context is in fact misleading me because it DOES momentarily create a temporary string table entry - i.e. one that would be corrupted by buffer deletion, but NOT by context deletion - ergo a temporary string table entry is created in the memory space of the eval caller by the eval perm itself. i.e. the sequence is in fact: a) create a temp string table entry, b) destroy the eval context, c) do the assignment. Rather than a) do the assignment, b) destroy the eval context. This does make sense. If I understand Mathias's test results correctly, 1 is true, 2 if false, 3 is not yet answered ...but I'm still trying to get my head around what Mathias's test-example and string table tool are actually telling me :-) I am slightly suspicious of his results, because he is not actually testing the original example: In his test he is using a buffer that is effectively in the eval - caller's memory space, which may change things (or not). Or is it? Also I'm not quite sure how you determine from the tool's output numbers whether the pollution is temporary or permanent (I'm a bit slow on the uptake, like that). So I guess the jury is still out on the question of usefulness - beyond the fact that it is fairly easy to read and understand the code and doesn't require globals, that is.
P.P.S. Sanity check: the original requirement is to create buffered data inside an eval, and then return it from the eval as buffered data, thus avoiding string table pollution. Easily done with global variables in the topmost context (which can be seen from within an eval), but not good form: Top-most namespace should be treated with "oodles" of respect, and not polluted with loads of arbitrarily named global variables created by Tom, Dick and Harry for their own nefarious purposes.
|
Re: Is this slightly scary use of "tempStringOf" viable? AlexTidmarsh - Wed May 27 21:34:11 EDT 2015 I have now been using this return mechanism in a real system since the date of the original post, and no-one has noticed any faults occurring, so I'm guessing the consensus is that, yes, it is viable - taking your point about its lifetime into account. After the discussion with Mathias, the question now becomes: is it actually beneficial? (Beyond the avoidance of using global variables and/or the use of hard-to-read constructs like the one Mathias demonstrated - and I have also used in the past, incidentally). Yes: the assignment direct from the eval_ result into a new buffer effectively ends the tempStringOf lifecycle started within the return_ and passed out of the eval_ there and then: noting in particular that there are no more statements in the evaluated script after the return_ and no other use made of the eval_ result other than to immediately put it into a buffer. So on the face of it, it (sort of) meets the limitations of use you have stated. Usage thus far has certainly not raised any errors.
From what Mathias has said, any temporary string table pollution caused during the evaluated script should also end immediately with the end of the eval_ context (along with any undeleted buffers, etc). So: not only does it appear to work as a transfer mechanism, it is possibly beneficial: noting that the "usual" way of doing this is for the "return_" to process an actual string (permanent? from the string table?) rather than a pointer into a buffer (tempStringOf). Although the only way to know if it is beneficial is to know whether the "normal" way pollutes the string table (temporarily or permanently) in the memory space (context) of the caller of the eval_. Mathias has effectively begged that question. In theory, the tempStringOf method I've proposed shouldn't even pollute it temporarily - but it is beginning to look like it does. Which means my assumption about the context destruction after the final assignment may be slightly wrong - and is being "masked" by the use of a temporary string table entry being created in the caller's memory space as part of the "tail-end" work of the eval_ perm.
P.S. Louie, if you do read the whole thread thus far, you'll notice the bit about deleting the buffer within the script and its effect on the preceding return_ and eventual final eval_ result, which suggested that the pointer is passed through "as-is" without putting it into a string table, temporarily or permanently. It also appeared to me that the final destruction of the memory space (i.e. context) of the evaluated script occurs just after the eval's final assignment. If it didn't, then this trick with tempStringOf wouldn't be working - in the same way that it doesn't if I expressly delete the buffer in the script. However - the question is begged by Mathias whether the transfer between return_ and eval_ at the very point of destroying the context is in fact misleading me because it DOES momentarily create a temporary string table entry - i.e. one that would be corrupted by buffer deletion, but NOT by context deletion - ergo a temporary string table entry is created in the memory space of the eval caller by the eval perm itself. i.e. the sequence is in fact: a) create a temp string table entry, b) destroy the eval context, c) do the assignment. Rather than a) do the assignment, b) destroy the eval context. This does make sense. If I understand Mathias's test results correctly, 1 is true, 2 if false, 3 is not yet answered ...but I'm still trying to get my head around what Mathias's test-example and string table tool are actually telling me :-) I am slightly suspicious of his results, because he is not actually testing the original example: In his test he is using a buffer that is effectively in the eval - caller's memory space, which may change things (or not). Or is it? Also I'm not quite sure how you determine from the tool's output numbers whether the pollution is temporary or permanent (I'm a bit slow on the uptake, like that). So I guess the jury is still out on the question of usefulness - beyond the fact that it is fairly easy to read and understand the code and doesn't require globals, that is.
P.P.S. Sanity check: the original requirement is to create buffered data inside an eval, and then return it from the eval as buffered data, thus avoiding string table pollution. Easily done with global variables in the topmost context (which can be seen from within an eval), but not good form: Top-most namespace should be treated with "oodles" of respect, and not polluted with loads of arbitrarily named global variables created by Tom, Dick and Harry for their own nefarious purposes.
I suspect the "useful and dependable solution"will be to
Back to your method:
Side note: "return_" is not the same as a "return" from a function. The 2nd takes action, the statement after "return" cannot be executed. "return_" simply stages the output string but does not terminate the eval_. Thus, you could add a line to "delete(theErrors_)" at line 6.1.
Les say this is all "mute" unless you figure to do 1000's of somewhat different huge eval_ calls with different huge results. line #8 [eval_(tempStringOf(dxlString))] is no doubt useful and dependable. <<unless you pass the addr_ of dxlString to the eval_ code itself and let it muck around with it in a self-evolving-code way. I think even MM would call that "voodoo">> Your line #6 is flawed as you are creating a real string by concatenating the EOL at the end of the tempStringof. Assuming you add line 5.5 theErrors_ += "\n" and then remove \n from the end of line 5: then line 6 [return_(tempStringOf(theErrors_))] is useful but not dependable. I think you will find that if you do processing before line #10 (calling other functions etc) that Buffer "result" ends up with garbage. Surely the space taken up with "theErrors_" is de-allocated with the eval_ context ends and can easily be re-used during these inserted functions. Seems MM's clever string table space evaluator is only useful in the main program (call before eval_, call after getting the "results"; compare) Who cares about the string table space inside eval_ if it all gets erased when finished. I remind you that "tempStringOf" is undocumented and IBM is free to change the way it works. -Louie |
Re: Is this slightly scary use of "tempStringOf" viable? AlexTidmarsh - Wed May 27 21:34:11 EDT 2015 I have now been using this return mechanism in a real system since the date of the original post, and no-one has noticed any faults occurring, so I'm guessing the consensus is that, yes, it is viable - taking your point about its lifetime into account. After the discussion with Mathias, the question now becomes: is it actually beneficial? (Beyond the avoidance of using global variables and/or the use of hard-to-read constructs like the one Mathias demonstrated - and I have also used in the past, incidentally). Yes: the assignment direct from the eval_ result into a new buffer effectively ends the tempStringOf lifecycle started within the return_ and passed out of the eval_ there and then: noting in particular that there are no more statements in the evaluated script after the return_ and no other use made of the eval_ result other than to immediately put it into a buffer. So on the face of it, it (sort of) meets the limitations of use you have stated. Usage thus far has certainly not raised any errors.
From what Mathias has said, any temporary string table pollution caused during the evaluated script should also end immediately with the end of the eval_ context (along with any undeleted buffers, etc). So: not only does it appear to work as a transfer mechanism, it is possibly beneficial: noting that the "usual" way of doing this is for the "return_" to process an actual string (permanent? from the string table?) rather than a pointer into a buffer (tempStringOf). Although the only way to know if it is beneficial is to know whether the "normal" way pollutes the string table (temporarily or permanently) in the memory space (context) of the caller of the eval_. Mathias has effectively begged that question. In theory, the tempStringOf method I've proposed shouldn't even pollute it temporarily - but it is beginning to look like it does. Which means my assumption about the context destruction after the final assignment may be slightly wrong - and is being "masked" by the use of a temporary string table entry being created in the caller's memory space as part of the "tail-end" work of the eval_ perm.
P.S. Louie, if you do read the whole thread thus far, you'll notice the bit about deleting the buffer within the script and its effect on the preceding return_ and eventual final eval_ result, which suggested that the pointer is passed through "as-is" without putting it into a string table, temporarily or permanently. It also appeared to me that the final destruction of the memory space (i.e. context) of the evaluated script occurs just after the eval's final assignment. If it didn't, then this trick with tempStringOf wouldn't be working - in the same way that it doesn't if I expressly delete the buffer in the script. However - the question is begged by Mathias whether the transfer between return_ and eval_ at the very point of destroying the context is in fact misleading me because it DOES momentarily create a temporary string table entry - i.e. one that would be corrupted by buffer deletion, but NOT by context deletion - ergo a temporary string table entry is created in the memory space of the eval caller by the eval perm itself. i.e. the sequence is in fact: a) create a temp string table entry, b) destroy the eval context, c) do the assignment. Rather than a) do the assignment, b) destroy the eval context. This does make sense. If I understand Mathias's test results correctly, 1 is true, 2 if false, 3 is not yet answered ...but I'm still trying to get my head around what Mathias's test-example and string table tool are actually telling me :-) I am slightly suspicious of his results, because he is not actually testing the original example: In his test he is using a buffer that is effectively in the eval - caller's memory space, which may change things (or not). Or is it? Also I'm not quite sure how you determine from the tool's output numbers whether the pollution is temporary or permanent (I'm a bit slow on the uptake, like that). So I guess the jury is still out on the question of usefulness - beyond the fact that it is fairly easy to read and understand the code and doesn't require globals, that is.
P.P.S. Sanity check: the original requirement is to create buffered data inside an eval, and then return it from the eval as buffered data, thus avoiding string table pollution. Easily done with global variables in the topmost context (which can be seen from within an eval), but not good form: Top-most namespace should be treated with "oodles" of respect, and not polluted with loads of arbitrarily named global variables created by Tom, Dick and Harry for their own nefarious purposes.
Its not that complicated, really. Just a hint on how to read the numbers: #include <C:/temp/petools.inc> #include <C:/temp/stringTable.inc> printStringTable(); string s = "xxx" // will generate 100 strings: xxxa, xxxaa, xxxaaa ... int i; for (i = 0; i < 100; i++) s = s " a " printStringTable(); // Here Count = ... will have increased by 100 This will give you something like:
52021 // <<-- The number of bins inside the string table (fixed, not so interesting) Now when you start that DXL script a second time, you will get the same numbers. That means, that after the start, the number of string table entries goes back to the number they were before the script, 17899. This is what I call temporary string table littering. And yes, inside an eval these kind of string table entries will be dismissed, when the eval_ ends. Now we modify our example, to generate permanent string table entries:
#include <C:/temp/petools.inc>
#include <C:/temp/stringTable.inc>
printStringTable();
Buffer buf = create(); buf = "xxx";
// will generate 100 strings: xxxa, xxxaa, xxxaaa ...
int i; for (i = 0; i < 100; i++) {
buf += 'a';
stringOf buf // will make the generated string permanent in the string table
}
printStringTable(); // Here Count = ... will have increased by 100
The very first time I run the script: Count = 17899 ... Count = 17999 // 100 entries made... The second time I run the script, I get: Count = 17999 ... Count = 17999 // No additional entries? So the first thing you notice, is that the first count is at the level of where the last script ended. This means the string table entries did not go back to the original value. That means, they are permanent! The next thing you need to notice is, that there were no additional antries created! Why? Because the strings xxxa, xxxaa, xxxaaa, ... were already inside the string table, and therefore were not added again! So there is two very important consequences from this: 1. Whenever you try to measure your string table entries, you need to be aware, that you can only do this reliably the first time you start the script. After that your strings have been persisted, and you will not measure them to be added again! You need to restart your client, to clear the string table, before measuring again. 2. eval_ does not save you from permanent string table entries. eval_ with using return_ is much worse because it might produce permanent string table entries, where you would have had temporary ones, or none (as in your tempStringOf example). eval_ might save you from lots of temporary string table entries, while your program is running - but I find that is not useful at all. The string table will not slow your program down considerably until you come into a million strings. And having a million temporary string table entries - is something I doubt I will observe in a real use DXL script. This amount of data, almost always comes from attribute values or other data sources. I which case you will again have to deal with permanent string table entries again. Hope that clears up this discussion - Summary: Using eval_ + return_ means more harm than use, but in most cases you will not even notice the problem, because string table slow down occurs much later than allocation leak slowdown. Regards, Mathias |